﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>ComObjGet()</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../css/default.css" rel="stylesheet" type="text/css">
</head>
<body>

<h1>ComObjGet() <span class="ver">[AHK_L 53+]</span></h1>
<p>返回到由 COM 组件提供的对象的引用.</p>
<pre class="Syntax">ComObject := ComObjGet(Name)</pre>

<h3>参数</h3>
<table class="info">
  <tr>
    <td>Name</td>
    <td>需要获取的对象的显示名称.参见 <a href="http://msdn.microsoft.com/en-us/library/ms691253.aspx">MkParseDisplayName (MSDN)</a> 了解更多信息.</td>
  </tr>
</table>

<h3>相关</h3>
<a href="ComObjCreate.htm">ComObjCreate</a>, <a href="ComObjActive.htm">ComObjActive</a>, <a href="ComObjConnect.htm">ComObjConnect</a>, <a href="ComObjError.htm">ComObjError</a>, <a href="http://msdn.microsoft.com/en-us/library/ms678805.aspx">CoGetObject (MSDN)</a>

<h3>示例</h3>
<pre class="NoIndent" id="exwmi"><em>; 示例:按下 Shift+Escape 来显示用于运行
;   活动窗口进程的命令行.需要 XP 或更高版本.</em>
+Esc::
    WinGet pid, PID, A
    <em>; 获取 WMI 服务对象.</em>
    wmi := <b>ComObjGet</b>("winmgmts:")
    <em>; 执行查询以获取匹配进程.</em>
    queryEnum := wmi.ExecQuery(""
        . "Select * from Win32_Process where ProcessId=" . pid)
        ._NewEnum()
    <em>; 获取首个匹配进程.</em>
    if queryEnum[process]
        MsgBox 0, Command line, % process.CommandLine
    else
        MsgBox Process not found!
    <em>; 释放所有全局对象 (使用局部变量时这个操作不是必须的).</em>
    wmi := queryEnum := process := ""
return
<em>; Win32_Process:<a href="http://msdn.microsoft.com/en-us/library/aa394372.aspx">http://msdn.microsoft.com/en-us/library/aa394372.aspx</a></em>
</pre>

</body>
</html>
